!pip install geopandas
Requirement already satisfied: geopandas in c:\users\silvi\anaconda3\lib\site-packages (0.14.1) Requirement already satisfied: pyproj>=3.3.0 in c:\users\silvi\anaconda3\lib\site-packages (from geopandas) (3.6.1) Requirement already satisfied: packaging in c:\users\silvi\anaconda3\lib\site-packages (from geopandas) (21.3) Requirement already satisfied: pandas>=1.4.0 in c:\users\silvi\anaconda3\lib\site-packages (from geopandas) (1.4.4) Requirement already satisfied: shapely>=1.8.0 in c:\users\silvi\anaconda3\lib\site-packages (from geopandas) (2.0.2) Requirement already satisfied: fiona>=1.8.21 in c:\users\silvi\anaconda3\lib\site-packages (from geopandas) (1.9.5) Requirement already satisfied: attrs>=19.2.0 in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (21.4.0) Requirement already satisfied: certifi in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (2022.9.14) Requirement already satisfied: importlib-metadata in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (4.11.3) Requirement already satisfied: cligj>=0.5 in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (0.7.2) Requirement already satisfied: click~=8.0 in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (8.0.4) Requirement already satisfied: setuptools in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (63.4.1) Requirement already satisfied: click-plugins>=1.0 in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (1.1.1) Requirement already satisfied: six in c:\users\silvi\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (1.16.0) Requirement already satisfied: pytz>=2020.1 in c:\users\silvi\anaconda3\lib\site-packages (from pandas>=1.4.0->geopandas) (2022.1) Requirement already satisfied: numpy>=1.18.5 in c:\users\silvi\anaconda3\lib\site-packages (from pandas>=1.4.0->geopandas) (1.21.5) Requirement already satisfied: python-dateutil>=2.8.1 in c:\users\silvi\anaconda3\lib\site-packages (from pandas>=1.4.0->geopandas) (2.8.2) Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\silvi\anaconda3\lib\site-packages (from packaging->geopandas) (3.0.9) Requirement already satisfied: colorama in c:\users\silvi\anaconda3\lib\site-packages (from click~=8.0->fiona>=1.8.21->geopandas) (0.4.5) Requirement already satisfied: zipp>=0.5 in c:\users\silvi\anaconda3\lib\site-packages (from importlib-metadata->fiona>=1.8.21->geopandas) (3.8.0)
import numpy as np
import pandas as pd
import geopandas as gpd
!pip install folium
import folium
from folium import plugins
import datetime
from IPython.display import HTML, display
from folium.plugins import TimestampedGeoJson
Requirement already satisfied: folium in c:\users\silvi\anaconda3\lib\site-packages (0.15.0) Requirement already satisfied: jinja2>=2.9 in c:\users\silvi\anaconda3\lib\site-packages (from folium) (2.11.3) Requirement already satisfied: numpy in c:\users\silvi\anaconda3\lib\site-packages (from folium) (1.21.5) Requirement already satisfied: requests in c:\users\silvi\anaconda3\lib\site-packages (from folium) (2.23.0) Requirement already satisfied: branca>=0.6.0 in c:\users\silvi\anaconda3\lib\site-packages (from folium) (0.7.0) Requirement already satisfied: MarkupSafe>=0.23 in c:\users\silvi\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (2.0.1) Requirement already satisfied: idna<3,>=2.5 in c:\users\silvi\anaconda3\lib\site-packages (from requests->folium) (2.10) Requirement already satisfied: certifi>=2017.4.17 in c:\users\silvi\anaconda3\lib\site-packages (from requests->folium) (2022.9.14) Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\silvi\anaconda3\lib\site-packages (from requests->folium) (3.0.4) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\silvi\anaconda3\lib\site-packages (from requests->folium) (1.25.11)
fp = r"C:\Users\silvi\Downloads\query.csv"
eartt=pd.read_csv(fp)
eartt.head()
| time | latitude | longitude | depth | mag | magType | nst | gap | dmin | rms | ... | updated | place | type | horizontalError | depthError | magError | magNst | status | locationSource | magSource | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2021-01-23T23:36:50.808Z | -61.8250 | -55.4937 | 9.58 | 6.9 | mww | NaN | 19.0 | 1.550 | 0.61 | ... | 2021-01-25T08:55:31.875Z | South Shetland Islands | earthquake | 7.4 | 2.7 | 0.043 | 52.0 | reviewed | us | us |
| 1 | 2021-01-21T12:23:05.774Z | 5.0074 | 127.5174 | 95.81 | 7.0 | mww | NaN | 28.0 | 2.813 | 0.82 | ... | 2021-01-24T22:57:52.349Z | 210 km SE of Pondaguitan, Philippines | earthquake | 7.0 | 5.0 | 0.069 | 20.0 | reviewed | us | us |
| 2 | 2021-01-19T02:46:22.380Z | -31.8232 | -68.8182 | 20.00 | 6.4 | mww | NaN | 21.0 | 0.299 | 0.99 | ... | 2021-01-26T04:16:44.654Z | 27 km SW of Pocito, Argentina | earthquake | 2.8 | 1.7 | 0.055 | 32.0 | reviewed | us | us |
| 3 | 2021-01-14T18:28:18.081Z | -2.9711 | 118.8893 | 18.00 | 6.2 | mww | NaN | 28.0 | 2.204 | 1.12 | ... | 2021-01-26T21:18:07.234Z | 32 km S of Mamuju, Indonesia | earthquake | 5.5 | 1.0 | 0.066 | 22.0 | reviewed | us | us |
| 4 | 2021-01-11T21:32:59.020Z | 51.2774 | 100.4370 | 10.00 | 6.7 | mww | NaN | 22.0 | 2.045 | 0.75 | ... | 2021-01-24T04:35:19.831Z | 30 km SSW of Turt, Mongolia | earthquake | 7.0 | 1.7 | 0.039 | 62.0 | reviewed | us | us |
5 rows × 22 columns
eartt1=eartt.rename({'time':'time_hour'}, axis=1)
eartt1.head()
| time_hour | latitude | longitude | depth | mag | magType | nst | gap | dmin | rms | ... | updated | place | type | horizontalError | depthError | magError | magNst | status | locationSource | magSource | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2021-01-23T23:36:50.808Z | -61.8250 | -55.4937 | 9.58 | 6.9 | mww | NaN | 19.0 | 1.550 | 0.61 | ... | 2021-01-25T08:55:31.875Z | South Shetland Islands | earthquake | 7.4 | 2.7 | 0.043 | 52.0 | reviewed | us | us |
| 1 | 2021-01-21T12:23:05.774Z | 5.0074 | 127.5174 | 95.81 | 7.0 | mww | NaN | 28.0 | 2.813 | 0.82 | ... | 2021-01-24T22:57:52.349Z | 210 km SE of Pondaguitan, Philippines | earthquake | 7.0 | 5.0 | 0.069 | 20.0 | reviewed | us | us |
| 2 | 2021-01-19T02:46:22.380Z | -31.8232 | -68.8182 | 20.00 | 6.4 | mww | NaN | 21.0 | 0.299 | 0.99 | ... | 2021-01-26T04:16:44.654Z | 27 km SW of Pocito, Argentina | earthquake | 2.8 | 1.7 | 0.055 | 32.0 | reviewed | us | us |
| 3 | 2021-01-14T18:28:18.081Z | -2.9711 | 118.8893 | 18.00 | 6.2 | mww | NaN | 28.0 | 2.204 | 1.12 | ... | 2021-01-26T21:18:07.234Z | 32 km S of Mamuju, Indonesia | earthquake | 5.5 | 1.0 | 0.066 | 22.0 | reviewed | us | us |
| 4 | 2021-01-11T21:32:59.020Z | 51.2774 | 100.4370 | 10.00 | 6.7 | mww | NaN | 22.0 | 2.045 | 0.75 | ... | 2021-01-24T04:35:19.831Z | 30 km SSW of Turt, Mongolia | earthquake | 7.0 | 1.7 | 0.039 | 62.0 | reviewed | us | us |
5 rows × 22 columns
type(eartt1.loc[0,'time_hour'])
str
eartt1['time_hour']=eartt1['time_hour'].str[:-5]
eartt1['time_hour']=pd.to_datetime(eartt1['time_hour'])
eartt1=eartt1.set_index('time_hour')
eartt1['type']= 'ss'
eartt1.head(1)
| latitude | longitude | depth | mag | magType | nst | gap | dmin | rms | net | ... | updated | place | type | horizontalError | depthError | magError | magNst | status | locationSource | magSource | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| time_hour | |||||||||||||||||||||
| 2021-01-23 23:36:50 | -61.825 | -55.4937 | 9.58 | 6.9 | mww | NaN | 19.0 | 1.55 | 0.61 | us | ... | 2021-01-25T08:55:31.875Z | South Shetland Islands | ss | 7.4 | 2.7 | 0.043 | 52.0 | reviewed | us | us |
1 rows × 21 columns
start = eartt1.pivot_table('id',
index = ['place', 'time_hour',
'latitude',
'longitude',
'mag'
],
columns = 'type',
aggfunc='count').reset_index()
start.head()
| type | place | time_hour | latitude | longitude | mag | ss |
|---|---|---|---|---|---|---|
| 0 | 0km SW of Loloan, Indonesia | 2018-08-05 11:46:38 | -8.2581 | 116.4375 | 6.9 | 1 |
| 1 | 0km W of Komerda, Indonesia | 2016-02-12 10:02:24 | -9.6338 | 119.4013 | 6.3 | 1 |
| 2 | 100 km ENE of Hachinohe, Japan | 2020-12-20 17:23:22 | 40.8667 | 142.5814 | 6.3 | 1 |
| 3 | 100 km NW of Constitución, Chile | 2020-11-22 00:54:56 | -34.5978 | -73.0596 | 6.1 | 1 |
| 4 | 100 km WNW of Kandrian, Papua New Guinea | 2020-10-01 10:34:45 | -5.9961 | 148.6656 | 6.1 | 1 |
start['time_hour']=pd.to_datetime(start['time_hour'])
start['time_hh']=start['time_hour'].dt.hour
start.head()
| type | place | time_hour | latitude | longitude | mag | ss | time_hh |
|---|---|---|---|---|---|---|---|
| 0 | 0km SW of Loloan, Indonesia | 2018-08-05 11:46:38 | -8.2581 | 116.4375 | 6.9 | 1 | 11 |
| 1 | 0km W of Komerda, Indonesia | 2016-02-12 10:02:24 | -9.6338 | 119.4013 | 6.3 | 1 | 10 |
| 2 | 100 km ENE of Hachinohe, Japan | 2020-12-20 17:23:22 | 40.8667 | 142.5814 | 6.3 | 1 | 17 |
| 3 | 100 km NW of Constitución, Chile | 2020-11-22 00:54:56 | -34.5978 | -73.0596 | 6.1 | 1 | 0 |
| 4 | 100 km WNW of Kandrian, Papua New Guinea | 2020-10-01 10:34:45 | -5.9961 | 148.6656 | 6.1 | 1 | 10 |
3352FF Blue
FCFF33 Yellow
FF33EC Pink
FF334C Red
start.loc[start['mag']<7, 'fillcolor']='#3352FF ' # Earthquakes with magnitude less than 7 = blue color
start.loc[start['mag']>=7, 'fillcolor']='#FF33EC' # Earthquakes with magnitude bigger or equal than 7 = pink color
start.loc[start['mag']>=8, 'fillcolor']='#FCFF33' # Earthquakes with magnitude bigger or equal than 8 = yellow color
start.loc[start['mag']>=9, 'fillcolor']='#FF334C' # Earthquakes with magnitude bigger or equal than 9 = red color
start.shape
(7488, 8)
start.head()
| type | place | time_hour | latitude | longitude | mag | ss | time_hh | fillcolor |
|---|---|---|---|---|---|---|---|---|
| 0 | 0km SW of Loloan, Indonesia | 2018-08-05 11:46:38 | -8.2581 | 116.4375 | 6.9 | 1 | 11 | #3352FF |
| 1 | 0km W of Komerda, Indonesia | 2016-02-12 10:02:24 | -9.6338 | 119.4013 | 6.3 | 1 | 10 | #3352FF |
| 2 | 100 km ENE of Hachinohe, Japan | 2020-12-20 17:23:22 | 40.8667 | 142.5814 | 6.3 | 1 | 17 | #3352FF |
| 3 | 100 km NW of Constitución, Chile | 2020-11-22 00:54:56 | -34.5978 | -73.0596 | 6.1 | 1 | 0 | #3352FF |
| 4 | 100 km WNW of Kandrian, Papua New Guinea | 2020-10-01 10:34:45 | -5.9961 | 148.6656 | 6.1 | 1 | 10 | #3352FF |
start['mag']= (start['mag'] - start['mag'].min())/(start['mag'].max()-start['mag'].min())
#df["A"] = (df["A"]-df["A"].min()) / (df["A"].max()-df["A"].min())
start['mag'].head()
0 0.290323 1 0.096774 2 0.096774 3 0.032258 4 0.032258 Name: mag, dtype: float64
def create_geojson_features(df):
features = []
for _, row in df.iterrows():
feature = {
'type': 'Feature',
'geometry': {
'type':'Point',
'coordinates':[row['longitude'],row['latitude']]
},
'properties': {
'time': pd.to_datetime(row['time_hh'], unit='h').__str__(),
'style': {'color' : ''},
'icon': 'circle',
'iconstyle':{
'fillColor': row['fillcolor'],
'fillOpacity': 0.8,
'stroke': 'true',
'radius': row['mag']*10
}
}
}
features.append(feature)
return features
start_geojson = create_geojson_features(start)
start_geojson[0]
{'type': 'Feature',
'geometry': {'type': 'Point', 'coordinates': [116.4375, -8.2581]},
'properties': {'time': '1970-01-01 11:00:00',
'style': {'color': ''},
'icon': 'circle',
'iconstyle': {'fillColor': '#3352FF ',
'fillOpacity': 0.8,
'stroke': 'true',
'radius': 2.9032258064516143}}}
EQ_map = folium.Map(location = [2, -2],
tiles = "CartoDB Positron",
zoom_start = 2)
plugins.ScrollZoomToggler().add_to(EQ_map)
icon_plane = plugins.BeautifyIcon(
icon="plane", border_color="#b3334f", text_color="#b3334f", icon_shape="triangle"
)
icon_number = plugins.BeautifyIcon(
border_color="#00ABDC",
text_color="#00ABDC",
number=10,
inner_icon_style="margin-top:0;",
)
folium.Marker(location=[50, -122], popup="Portland, OR", icon=icon_number).add_to(EQ_map)
plugins.Fullscreen(
position="topright",
title="Expand me",
title_cancel="Exit me",
force_separate_button=True,
).add_to(EQ_map)
TimestampedGeoJson(start_geojson,
period = 'PT1H',
duration = 'PT1H',
transition_time = 1000,
auto_play = True).add_to(EQ_map)
EQ_map
EQ_map.save('EQ_map.html', title='Earthquakes with Magnitude 6 and higher since 1968')